package com.enation.app.web.core.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.enation.app.web.core.model.VisitorWebSite;
import com.enation.app.web.core.service.IVisitorWebSiteManager;
import com.enation.framework.database.IDaoSupport;

/**
 * 
 * @function 网站访问管理
 * @author 闯哥
 * @time 2016年10月16日 下午6:33:18
 * 
 */
@Service
public class VisitorWebSiteManager implements IVisitorWebSiteManager {

	private String TABLE = "es_visitorwebsite";

	@Autowired
	private IDaoSupport<VisitorWebSite> daoSupport;

	@Override
	public VisitorWebSite getVisitorBytime(String time) {
		String sql = "select * from es_visitorwebsite where time=?";
		return this.daoSupport.queryForObject(sql, VisitorWebSite.class, time);
	}

	@Override
	public void insertVisitor(VisitorWebSite visitorWebSite) {
		this.daoSupport.insert(TABLE, visitorWebSite);

	}

	@Override
	public void updateVisitor(VisitorWebSite visitorWebSite) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("time", visitorWebSite.getTime());

		this.daoSupport.update(TABLE, visitorWebSite, map);

	}

	// 获取7天浏览量数据
	@Override
	public List<Map> getState1PageView() {
		String sql = "select * from " + TABLE + " order by time desc";
		List<Map> visitorWebSites = this.daoSupport.queryForListPage(sql, 1, 7,
				null);
		return visitorWebSites;
	}

	@Override
	public VisitorWebSite getVisitorOne() {
		String sql = "select * from " + TABLE + " order by time desc limit 1";
		return this.daoSupport.queryForObject(sql, VisitorWebSite.class, null);
	}

}
